<?php
	require_once($_SERVER['DOCUMENT_ROOT'].'uno-course-scheduler/include/config.inc.php');
	require_once($_SERVER['DOCUMENT_ROOT'].'uno-course-scheduler/include/top.inc.php');

$building_id = mysql_real_escape_string(strip_tags($_GET['bid']));
$classroom_id = mysql_real_escape_string(strip_tags($_GET['id']));

$get_building_data = mysql_query("SELECT * FROM buildings WHERE id = $building_id");
$building_name = mysql_result($get_building_data,0,'building_name');
$abbreviation = mysql_result($get_building_data,0,'abbreviation');

$get_classroom_data = mysql_query("SELECT * FROM classrooms WHERE id = $classroom_id");
$room_num = mysql_result($get_classroom_data,0,'room_num');


echo '<p>';
	echo "<a href='../index.php?id=$building_id'>&lt;&lt; Back to Classrooms Portal</a><br />";
echo '</p>';
echo "<h1>Classroom Closings for $abbreviation $room_num</h1>";
echo '<p>';
//creates link/button for add Closing
echo "<a href='add.php?cid=$classroom_id'>Add Closing</a>";
echo '</p>';

//counting variable
$i = 0;

//select statement
$query="SELECT * FROM classroom_closings WHERE classroom_id = $classroom_id ORDER BY day_id, start_time";
$result=mysql_query($query);

//determine dynamically number of rows read from table
$num_rows=mysql_numrows($result);

if ($num_rows > 0)
{

	//start table
	echo "<table class=\"postSchedule\">";
	
		//create table row with column ID's
		echo "<tr>";
			echo "<td style='text-align: center'><b>Day</b></td>";
			echo "<td style='text-align: center'><b>Start Time</b></td>";
			echo "<td style='text-align: center'><b>End Time</b></td>";
			echo "<td style='text-align: center'></td>";
		echo "</tr>";

	//loop to walk through and print to screen all entries in timeslots table
	$row_count = 0;
	while ($i < $num_rows) 
	{
		$row_count++;
		$closing_id=mysql_result($result,$i,"classroom_closing_id");
		$starttime=mysql_result($result,$i,"start_time");
		$endtime=mysql_result($result,$i,"end_time");
		$day_id=mysql_result($result,$i,"day_id");

		$get_day=mysql_query("SELECT * FROM days WHERE id = '$day_id'");
		$day_name=mysql_result($get_day,0,'day_name');
		
		//generate table row for each timeslot on each iteration of the loop
		echo "<tr";
		if (($row_count%2) != 0) echo " class=\"zebra_stripe\"";
		echo ">";
			echo "<td style='text-align: center'>$day_name</td>";	
			echo "<td style='text-align: center'>".date('g:ia', strtotime($starttime))."</td>";		
			echo "<td style='text-align: center'>".date('g:ia', strtotime($endtime))."</td>";
					
			echo "<td>";		//cell containing form for delete timeslot link/button
				echo "<a href='delete.php?bid=$building_id&amp;cid=$classroom_id&amp;id=$closing_id'>Delete</a>";
			echo "</td>";
	
		echo "</tr>";
		
		//increment counting variable
		$i++;
	}

	//end table tag
	echo "</table>";

}
else
{
	echo "<p><b>NO CLOSINGS CURRENTLY SCHEDULED FOR ROOM</b></p>";
}

?>

<?php
	require_once($_SERVER['DOCUMENT_ROOT'].'uno-course-scheduler/include/bottom.inc.php');
?>